﻿<%@ CODEPAGE=65001 %>
<%
'///////////////////////////////////////////////////////////////////////////////
'// 插件应用:    Z-Blog 2.0 其它版本未知
'// 插件制作:    狼的旋律(http://www.wilf.cn) / zsx(http://www.zsxsoft.com)
'// 备    注:    相册首页
'// 最后修改:
'// 最后版本:
'///////////////////////////////////////////////////////////////////////////////
%>
<% 'Option Explicit %>
<% 'On Error Resume Next %>
<% Response.Charset="UTF-8" %>
<% Response.Buffer=True %>
<!-- #include file="../../c_option.asp" -->
<!-- #include file="../../../zb_system/function/c_function.asp" -->
<!-- #include file="../../../zb_system/function/c_system_lib.asp" -->
<!-- #include file="../../../zb_system/function/c_system_base.asp" -->
<!-- #include file="../../../zb_system/function/c_system_plugin.asp" -->
<!-- #include file="../../plugin/p_config.asp" -->
<%
Call System_Initialize()
Call WindsPhoto_Initialize()

If CheckpluginState("windsphoto") = False Then Call ShowError(48)

Function GetPhotoIndex()
    Dim ipagecount,ipagecurrent,irecordsshown
    If request.querystring("page") = "" Then
        ipagecurrent = 1
    Else
        If IsNumeric(request.querystring("page")) = False Then ShowError(3)
		ipagecurrent = CInt(request.querystring("page"))
    End If

    Dim sql
    If WP_ORDER_BY = "0" Then
        sql = "select * FROM WindsPhoto_zhuanti where pass<>'no' order by ordered,id asc"
    Else
        sql = "select * from WindsPhoto_zhuanti where pass<>'no' order by ordered,id asc "
    End If
    Set objRs = Server.CreateObject("ADODB.Recordset")
    objRs.pagesize = WP_INDEX_PAGERCOUNT
    objRs.Open sql, objConn, 1, 1
    ipagecount = objRs.pagecount
    If ipagecurrent > ipagecount Then ipagecurrent = ipagecount
    If ipagecurrent < 1 Then ipagecurrent = 1
    If ipagecount = 0 Then
        GetPhotoIndex = GetPhotoIndex&"<p align=""center"">没有任何相册</p>"
    Else
        objRs.absolutepage = ipagecurrent
        irecordsshown = 0
        GetPhotoIndex = GetPhotoIndex &"<div class=""wp_intro"">"& WP_ALBUM_INTRO &"</div>"& VBCRLF
        GetPhotoIndex = GetPhotoIndex&"<table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""5"">" & VBCRLF
        Do While irecordsshown<WP_INDEX_PAGERCOUNT And Not objRs.EOF
            GetPhotoIndex = GetPhotoIndex&"<tr align=""center"">"

            For i = 1 To 3

                If Not objRs.EOF Then
					'获取相册封面
					Set temprs = objConn.Execute("select top 1 * FROM WindsPhoto_desktop where zhuanti="&objRs("id")&" and hot<>0 order by id asc")
                    If temprs.EOF Or temprs.bof Then
                        surl = "images/notop.gif"
                    Else
                        surl = temprs("surl")
						If Left(surl, 4)<>"http" Then surl = WP_SUB_DOMAIN & surl
                    End If
					'获取加密相册封面
					Set temprs = objConn.Execute("select pass FROM WindsPhoto_zhuanti where id="&objRs("id"))
                    pass = temprs("pass")
                    If pass<>"" Then
                        surl = WP_SUB_DOMAIN &"images/nopass.gif"
                    End If
					'获取相册图片数量
                    Set temprs = objConn.Execute("select count(*) as C FROM WindsPhoto_desktop where zhuanti="&objRs("id"))
                    sm = temprs("c")
                    GetPhotoIndex = GetPhotoIndex&"<td width=""33%""><a href="""& WP_SUB_DOMAIN &"album.asp?typeid="&objRs("id")&""" title="""&objRs("name")&"""><img class=""wp_top"" src="""&surl&""" alt="""&objRs("name")&""" /></a><br /><a href="""& WP_SUB_DOMAIN &"album.asp?typeid="&objRs("id")&""" title="""&objRs("name")&""">"&objRs("name")&" | "&sm&"张</a></td>" & VBCRLF
                    irecordsshown = irecordsshown + 1
                    objRs.movenext
                End If

            Next

            GetPhotoIndex = GetPhotoIndex&"</tr>" & VBCRLF
        Loop
    End If
    GetPhotoIndex = GetPhotoIndex&"</table>" & VBCRLF

	'分页
    If ipagecount >1 Then
        GetPhotoIndex=GetPhotoIndex&"<div class=""post pagebar"">"
		GetPhotoIndex=GetPhotoIndex&"<a href=""default.asp""><span class=""page first-page"">1</span></a>"
        if ipagecurrent=1 Then
            GetPhotoIndex=GetPhotoIndex&"<span class=""page other-page"">«</span>"
        else
            GetPhotoIndex=GetPhotoIndex&"<a title=""上一页"" href=""?page="&ipagecurrent-1&"""><span class=""page"">«</span></a>"
        End If

        for i = 1 to ipagecount
        ipagenow = ipagenow + 1
        If ipagecurrent=ipagenow then
            GetPhotoIndex=GetPhotoIndex&"<span class=""page now-page"">"&ipagenow&"</span>"
        Else
			GetPhotoIndex=GetPhotoIndex&"<a href=""?page="&ipagenow&"""><span class=""page"">"&ipagenow&"</span></a>"
		End If
        next
		
		If ipagecount>ZC_PAGEBAR_COUNT Then
			a=ipagecurrent-Cint((ZC_PAGEBAR_COUNT-1)/2)
			b=ipagecurrent+ZC_PAGEBAR_COUNT-Cint((ZC_PAGEBAR_COUNT-1)/2)-1
			If a<=1 Then
				a=1:b=ZC_PAGEBAR_COUNT
			End If
			If b>=ipagecount Then
				b=ipagecount:a=ipagecount-ZC_PAGEBAR_COUNT+1
			End If
		Else
			a=1:b=ipagecount
		End If

		For i = a to b
			If ipagecurrent = i Then
				GetPhoto=GetPhoto&"<span class=""page now-page"">"&i&"</span>"
			Else
				GetPhoto=GetPhoto&"<a href=""?typeid="&typeid&"&mo="&mo&"&page="&i&"""><span class=""page"">"&i&"</span></a>"
			End If
		Next

        If ipagecount>ipagecurrent then
            GetPhotoIndex=GetPhotoIndex&"<a title=""下一页"" href=""?page="&ipagecurrent+1&"""><span class=""page"">»</span></a>"
        Else
            GetPhotoIndex=GetPhotoIndex&"<span class=""page"">»</span>"
        End If

        GetPhotoIndex=GetPhotoIndex&"<a title=""尾页"" href=""default.asp?page="&ipagecount&"""><span class=""page last-page"">"&ipagecount&"</span></a></div>" & VBCRLF
    End If

    objRs.Close
    Set objRs = Nothing

End Function

Dim objArticle
Set objArticle = New TArticle
objArticle.FType=ZC_POST_TYPE_PAGE
If GetTemplate("TEMPLATE_WP_INDEX")<>empty Then objArticle.template = "WP_INDEX"
objArticle.Title = WP_ALBUM_NAME
objArticle.Content = GetPhotoIndex()
If objArticle.Export(ZC_DISPLAY_MODE_SYSTEMPAGE) Then
	objArticle.Build
    Dim Html, AddedHtml
    Html = objArticle.html
    AddedHtml = "<link rel=""alternate"" type=""application/rss+xml"" href="""& WP_SUB_DOMAIN &"rss.asp"" title=""订阅我的相册"" />" & VBCRLF
    AddedHtml = AddedHtml & "<link rel=""stylesheet"" href="""& WP_SUB_DOMAIN &"images/windsphoto.css"" type=""text/css"" media=""screen"" />" & VBCRLF
	AddedHtml = AddedHtml & "<style type=""text/css"">img.wp_top,img.wp_small{max-width:"& WP_SMALL_WIDTH &"px !important;max-height:"& WP_SMALL_HEIGHT &"px;}</style>" & VBCRLF & "<title>"
    Html = Replace(Html, "<title>", AddedHtml)
    Html = Replace(Html, ">Powered By", ">Powered By <a href=""http://www.windsphoto.com"" target=""_blank"" title=""WindsPhoto官方网站"">WindsPhoto</a> &amp;")
    Call ClearGlobeCache
    Call LoadGlobeCache
    Response.Write Html
End If
Set objArticle = Nothing

Call System_Terminate()

If Err.Number<>0 then
	Call ShowError(0)
End If
%>